import { api } from "../api"
import type { FetchProjectsParams } from '@/views/Square/InnovationSquare/projectDisplay/home/types/FetchProjectsParams';
import { message } from "ant-design-vue";

export async function fetchAllProjectApi(params: FetchProjectsParams) {
  try {
    const response = await api.post('/java/ground/innovationPlaza/project/getALLProjects', params);
    if (response) {
      const res = { records: response.data.records, pages: response.data.pages, total: response.data.total }
      return res
    }

    else { message.error('获取项目资料失败'); }
  }
  catch (error) {
    throw new Error('获取项目资料失败')
  }
}

export async function getProjectDetailsMetaApi(projectId: string) {
  try {
    return api.get('/java/ground/innovationPlaza/project/getProjectDetailsMeta', {
      params: {
        projectId: Number(projectId),
      },
    });
  }
  catch (error) {
    throw new Error('获取项目资料-基本资料失败')
  }
}

export async function getProjectDetailsIntroduceApi(projectId: string) {
  try {
    return api.get('/java/ground/innovationPlaza/project/getProjectDetailsIntroduce', {
      params: {
        projectId: Number(projectId),
      },
    });
  }
  catch (error) {
    throw new Error('获取项目资料-介绍失败')
  }
}

export async function getProjectDetailsmembersApi(projectId: string) {
  try {
    const response = await api.get('/java/ground/innovationPlaza/project/getProjectDetailsmembers', {
      params: {
        projectId: Number(projectId),
      },
    });
    if (response.data)
      return response.data;

    else return []
  }
  catch (error) {
    throw new Error('获取项目资料-成员失败')
  }
}

export async function getCommonProjectTagsApi() {
  try {
    const res = await api.get('/java/ground/innovationPlaza/project/getCommonProjectTags');
    const resp = { tag: res.data }
    return resp
    // const proxyList: string[] = response.data.map((tag: { tagId: string, name: string; tagType: string }) => tag.name);
    // const res = { tags: proxyList }
    // return res
  }
  catch (error) {
    throw new Error('获取项目资料失败')
  }
}
